﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
//using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;

namespace School
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            // 假设这里的 checkedListBoxLayer、progressBar1 和 btnRun 已经在设计器中定义
            // 你需要确保这些控件存在，或者根据实际情况调整
            // Weight weight = new Weight(checkedListBoxLayer, progressBar1, btnRun);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
        {
            // 这里可以编写具体的处理逻辑，目前先留空
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 关闭当前窗体并退出应用程序
            Application.Exit();
        }

        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 仅关闭当前窗体，不退出应用程序
            this.Close();
        }

        private void 欧氏距离ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DistanceSettingsForm form = new DistanceSettingsForm(axMapControl1);
            form.ShowDialog();
        }

        private void 栅格转面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (RasterToPolygonForm form = new RasterToPolygonForm(axMapControl1))
            {
                form.ShowDialog();
            }
        }

        private void 按属性选择图层ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (AttributeSelectionForm form = new AttributeSelectionForm(axMapControl1))
            {
                form.ShowDialog();
            }
        }

        private void 坡度ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Slope form = new Slope(axMapControl1);
            form.ShowDialog();
        }

        private void 打开mxdToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //文件路径名称,包含文件名称和路径名称
            string strName = null;

            //定义OpenFileDialog，获取并打开地图文档
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开MXD";
            openFileDialog.Filter = "MXD文件（*.mxd）|*.mxd";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                strName = openFileDialog.FileName;
                if (strName != "")
                {
                    this.axMapControl1.LoadMxFile(strName);
                    axMapControl1.ActiveView.Refresh(); // 刷新地图控件
                }
            }
            //地图文档全图显示
            this.axMapControl1.Extent = this.axMapControl1.FullExtent;
        }

        private void 添加数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 这里可以添加添加数据的逻辑
        }

        private void 加权叠加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ESRI.ArcGIS.Controls.AxMapControl axMapControl = axMapControl1;
            ESRI.ArcGIS.Controls.IMapControl3 mapControl = axMapControl.Object as ESRI.ArcGIS.Controls.IMapControl3;
            if (mapControl != null)
            {
                Weight weight = new Weight(mapControl);
                weight.ShowDialog();
            }
            else
            {
                MessageBox.Show("地图控件转换出错，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void 重分类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var mapControl = axMapControl1.Object as IMapControl3;
                ReclassifyForm reclassifyForm = new ReclassifyForm(mapControl.Map);
                reclassifyForm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开重分类工具: " + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}